package CH01数组结构.LeetCode双指针;

public class LC1147 {
    public int longestDecomposition(String text) {
        int count = 0;
        char[] ch = text.toCharArray();
        int i = 0;
        int j = ch.length - 1;
        String s1 = "";
        String s2 = "";
        while (i < j) {
            s1 += ch[i++];
            s2 = ch[j--] + s2;
            if (s1.equals(s2)) {
                count += 2;
                s1 = "";
                s2 = "";
            }
        }
        if (i == j || !s1.equals("")) {
            count++;
        }
        return count;
    }
}